package javaframework;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

import framework.ImageWrapper;
import framework.ResourcesWrapper;

public class JavaResources implements ResourcesWrapper {

	private final String my_imagePath;
	public JavaResources(final String the_imagePath) {
		my_imagePath = the_imagePath;
	}

	@Override
	public ImageWrapper loadImage(final String the_path) {
		BufferedImage img = null;
		//System.out.println("Loading " + the_path);
		try {
			img = ImageIO.read(getClass().getResource(my_imagePath + the_path));
		} catch (IllegalArgumentException e) {
			throw new IllegalArgumentException("Could not load image at path " + my_imagePath + the_path);
		} catch (IOException e){
			throw new IllegalArgumentException("Could not load image at path " + my_imagePath + the_path);
		}
		int width = img.getWidth();
		int height = img.getHeight();
		BufferedImage temp = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_ARGB);
		temp.getGraphics().drawImage(img, 0, 0, width, height, null);
		return new JavaImage(temp);
	}

}
